package com.onpositive.wiki3.db.catmodel;

import com.onpositive.nlp.sequence.IDefinitionExtractor;
import com.onpositive.wiki3.db.IWikiDB;

public class PrimaryTextFinder {

	public static String getText(IWikiDB db, String text) {
		try {
			IDefinitionExtractor ext = (IDefinitionExtractor) Class.forName(
					"storage.v1.DefinitionExtractor").newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		int[] fuzzyMatches = db.getTitleMapper().getFuzzyMatches(text);
		if (fuzzyMatches != null && fuzzyMatches.length > 0) {
			int redirect = db.getRedirectAccess().getRedirect(fuzzyMatches[0]);
			if (redirect != -1) {
				return db.getContentAccessor().getTextContent(redirect);
			}
			return db.getContentAccessor().getTextContent(fuzzyMatches[0]);
		}
		return text;
	}
}
